package org.example;

import org.apache.http.HttpHost;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

/**
 * Hello world!
 *
 */
public class ES_Doc_Update_05 {
    public static void main( String[] args ) throws Exception {
        // 创建ES客户端
        RestHighLevelClient client = new RestHighLevelClient(RestClient.builder
                (new HttpHost("localhost", 9200, "http")));
        // 插入数据
        UpdateRequest request = new UpdateRequest();
        request.index("user").id("1001");
        request.doc(XContentType.JSON,"sex","女");

        UpdateResponse response = client.update(request, RequestOptions.DEFAULT);

        // 响应状态
        System.out.println(response.getResult());
        client.close();
    }
}
